@extends('home.base.goods')
@section('content')
<script type="text/javascript" src="{{ asset('publics/jquery-1.8.3.min.js') }}"></script>
<style type="text/css">
    td{
       padding-top:20px;
       padding-bottom:20px 
    }
    table{
        background:#F5F5F5;
        /*border:1px solid red;*/
        width:85%;
        padding-top:200px
    }
    img{
        width:60px;
    }
</style>
         <!-- <table class="tile table table-bordered table-striped"> -->
<div class="site-header site-mini-header">
    <div class="container">
        <div class="header-logo">
        <a class="logo ir" href="//www.mi.com/index.html" title="小米官网" data-stat-id="f4006c1551f77f22" onclick="_msq.push(['trackEvent', '08fae3d5cb3abaaf-f4006c1551f77f22', '//www.mi.com/index.html', 'pcpid']);">小米官网</a>
        </div>
    <div id="J_miniHeaderTitle" class="header-title has-more">
        <h2>我的购物车</h2>
        <p>温馨提示：产品是否购买成功，以最终下单为准哦，请尽快结算</p>
    </div>
    <div class="topbar-info" id="J_userInfo">
        <h3>
            @if(session('homeuser'))
            <span class="ji" style="color:pink">hello!  {{ session('homeuser')->username}}</span>
                  &nbsp;<a class="ji" href="{{ url('home/info') }}">个人中心</a>&nbsp;
            @endif
            <span class="ji" class="sep"></span>
            <a class="link link-order ji" rel="nofollow" href="{{ url('home/order') }}" target="_blank">我的订单</a>
            @if (count($errors) > 0)
                @foreach ($errors->all() as $error)
                    <a style="color:red">{{ $error }}</a>
                @endforeach
            @endif
            <a class="ji" href="{{ url('home/foot') }}?userid={{ $userid }}">我的足迹</a>&nbsp;
        </h3>
    </div>
     <h2 style="color:red">
        @if(session('msg'))
            {{session("msg")}}
        @endif   
    </h2>
</div>
</div>
    <center>
        <div class="block-area" id="tableStriped" style="color:black">
                <form action="" method="post" name="myform">
                    <input type="hidden" name="_token" value="{{ csrf_token() }}">
                    <input type="hidden" name="_method" value="DELETE">
                </form>
                <div class="table-responsive overflow">
                <form action="" method="post" name="meform">
                <input type="hidden" name="_token" id="token" value="{{ csrf_token() }}">
                        <table>
                            <thead>
                                <tr>
                                    <td align="center">
                                    <input type="checkbox" id='check' onclick="doCheck()" value="全选">
                                        全选(购物车id)
                                    </td>
                                     <td align="center">　　</td>
                                    <td align="center">商品名称</td>
                                    <td align="center">商品颜色</td>
                                    <td align="center">商品单价</td>
                                    <td align="center">数量</td>
                                    <td align="center">用户id</td>
                                    <td align="center">小计</td>
                                    <td align="center">操作</td>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach($list as $v)
                                    <tr>
                                        <td align="center"  class="crid">
                                        {{ $loop->iteration }}
                                    <input type="checkbox" class='che' id="che{{ $loop->iteration }}" value="{{ $v->goodsprice }}" onclick="doChe({{ $loop->iteration }})">
                                    <input type="hidden" id="carid{{ $loop->iteration }}" value="{{ $v->carid }}">
                                       </td>
                                       <td align="center"><a href='{{ url("/home/detxiaomi5splus") }}?id={{$v->goodsid}}'><img src='{{ url("uploads")}}/{{ "$v->goodspic" }}'></a></td>
                                        <td align="center"  class="goodsname">
                                            <p>{{ $v->goodsname }}</p>
                                            <p style="color:red">{{$v->goodsversion }}</p>
                                        </td>
                                        <td align="center">{{ $v->goodscolor }}</td>
                                        <td align="center" class="goodsprice" id="pri{{ $loop->iteration }}">{{ $v->goodsprice }}元</td>
                                        <td align="center">
                                    <input type="number" max="30" min="1" value="{{ $v->goodsnum }}" id="num{{ $loop->iteration }}" class="donum" onblur="doNumber({{ $loop->iteration }})" onclick="doNum({{ $loop->iteration }})" style="width:50px"> 
                                        </td>
                                        <td align="center">{{ $v->userid }}</td>
                                        <td align="center" id="total{{ $loop->iteration }}" >{{ $v->goodsprice*$v->goodsnum }}元</td>
                                        <td align="center">
                                            <a class="ji" href="javascript:doDele({{ $v->carid }})">
                                               取消
                                            </a>&nbsp;&nbsp;&nbsp;&nbsp;
                                        </td>
                                     </tr>
                                 @endforeach
                                </tbody>
                            </table>
                        <script type="text/javascript">
                            function doDele(id){
                                if(confirm('取消')){
                                    var form = document.myform;
                                    form.action = '/home/car/'+id;
                                    form.submit();
                                    var num = $(this).val();
                                    // alert(pri*num);
                                }
                            }
                            function doChe(id){
                                var che = document.getElementById('che'+id).checked;
                                if (che) {
                                    document.getElementById('che'+id).name="goodsprice"+id;
                                    document.getElementById('carid'+id).name="carid"+id;
                                    document.getElementById('num'+id).name="goodsnum"+id;
                                }
                            }
                            function doCheck(){
                                var aa = document.getElementById('check').checked;
                                    // if($('#check').){}
                                 // console.log($('tab').('#check'));
                                 if(aa){
                                    var list = document.getElementsByTagName('input');
                                    for (var i = 0; i < list.length; i++) {
                                        if(i != 0){
                                            list[i].checked = true;
                                        }
                                    }
                                }else{
                                    var list = document.getElementsByTagName('input');
                                    for (var i = 0; i < list.length; i++) {
                                        if(i != 0){
                                            list[i].checked = false;
                                        }
                                    }
                                }
                            }
                            function doNum(id){
                                if ($('#num'+id).val()>0 && $('#num'+id).val()<31) {
                                    var num = $('#num'+id).val();
                                    var pri = parseFloat($('#pri'+id).html());
                                    $('#total'+id).html(num*pri+'元');
                                    $('#che'+id).val(num*pri);
                                }
                            }
                             function doNumber(id){
                                if ($('#num'+id).val()>0 && $('#num'+id).val()<31) {
                                    var num = $('#num'+id).val();
                                    var pri = parseFloat($('#pri'+id).html());
                                    $('#total'+id).html(num*pri+'元');
                                    $('#che'+id).val(num*pri);
                                }
                            }
                            function doSett(){
                                document.meform.action = "/home/caredit";
                                document.meform.submit();
                            }

                            var ji = $(".ji");
                            ji.mouseover(function (){
                                $(this).css('background','#FF6700');
                            }).mouseout(function() {
                                $(this).css('background','');
                            });                           
                        </script>
                            <div id="J_cartBar" class="cart-bar clearfix cart-bar-fixed">
                                <h2 style="color:red">
                                @if(session('msg'))
                                    {{session("msg")}}
                                @endif   
                                </h2>
                                <div class="section-left">
                                    <a class="btn btn-a btn btn-primary" href="{{ url('/home')}}" data-stat-id="a4887072ccf6c1d5">继续购物</a>
                                    <a class="btn btn-a btn btn-primary" data-stat-id="a4887072ccf6c1d5" onclick="doSett()">去结算</a>
                                        <div id="J_noSelectTip" class="no-select-tip hide">
                                            请勾选需要结算的商品     
                                            <i class="arrow arrow-a"></i>
                                            <i class="arrow arrow-b"></i>
                                        </div>
                                </div>
                            </div>
                    </form> 
                </div>          
        </div>
    </center>
@stop
